<template>
  <div class="exam index" v-loading='loading'>
            <div class='bts-group'>
              <el-button v-for='(item,index) in uploadType'
                         :key='index'
                        @click='goPath(item.path)'
                         :class='activeIndex2==index ? "sure":""'>{{item.name}}</el-button>
            </div>
            <h3 class="table-name"> 应急预案个人评审意见表</h3>
           <Table :data='data'  :suggest='suggest' :remark='remark' @sendRemark='acceptRemark' @sendSuggest='acceptSuggest' :signImg='[signImg]' ></Table>
            <div class="bts">
              <el-button class='sure' @click="saveData(0)">保存</el-button>
                <el-button class='sure' @click="startSend" v-if="flag">{{identity=='1' ? '评审意见汇总' :'发送组长'}}</el-button>
                <el-button class='sure' v-else >{{identity=='1' ? '评审意见汇总' :'发送组长'}}</el-button>
            </div>
          </div>
</template>

<script>
import Table from './common/table4'
import config from '../../config.js'
import { setTimeout } from 'timers';
export default {
  components: {
    Table,
  },
  data () {
    return {
      data:[],
      varCompanyName:'',
      remark: '',
      identity:'',
      signImg:'',
      suggest:'',
      flag:true,
      time: null,
      name: '',
      planSummaryId:'',
      reviewTemplateName:'',
      uploadType: [
        {
          name: '形式评审',
          path: 'situationexam2'
        },
        {
          name: '要素评审',
          path: 'keyexam2'
        },
        {
          name: '附件要素评审',
          path: 'powerexam2'
        },
        {
          name: '个人评审意见',
          path: 'personexam2'
        }
      ],
      activeIndex2: 3,
      autograph:'',
      loading:false,
    };
  },
  mounted(){
    this.getData()
  
      this.signImg = localStorage.signImg
      this.autograph = localStorage.autograph
      this.identity = localStorage.identity
       this.$nextTick(()=>{
      document.querySelector('.left-box').style.height='726px'
    })
  },
  methods:{
    acceptSuggest(val){
      this.suggest=val
    },
     acceptRemark(val){
       this.remark=val
    },
    goPath(path){
      this.saveData(0,path)
    },
 
  saveData(n,path){
if( this.suggest=='' ){

this.$message.warning('专家建议不能为空')
}else{
 this.postData(2,8,[], this.autograph,this.suggest ,this.remark)
          .then(res => {
            if (res.data.meta.success) {
              if(n==0){
   this.$message.success(res.data.meta.message)
                 if(path){
                   this.$router.push(path)
                 }
              }else{
                  this.sendData()
              }
           
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
}
  },
  startSend(){
    
if( this.suggest=='' ){

this.$message.warning('专家建议不能为空')
}else{
    this.flag=false
    var t = 10;
     this.time = setInterval(() => {
          t--;
          if (t != 0) {
           
          } else {
            t = 0;
            clearInterval(this.time);
            this.flag = true;
          }
        }, 1000);
    this.saveData(1)  
}
      
  },
 sendData(){
   let url = config.baseUrl +'emergency/v1.0/review/send'
      this.$axios
          .post(url, {
             planSummaryId: localStorage.planid,
               userId:localStorage.userid
          })
          .then(res => {
            if (res.data.meta.success) {
              var msg = '发送成功'
              if(localStorage.identity==1){
                msg='发送成功,请在已评审模块进行意见汇总'
              }
              this.$message.success(msg)
              setTimeout(()=>{
                  this.$router.push('/assessed2')
              },1000)
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
    },
     getData(){
       this.loading=true
       this.postData(0,8)
        .then( res=> {
          this.loading=false
            if (res.data.meta.success) {
               this.data = res.data.data.list
                 this.varCompanyName = res.data.data.companyName
               res.data.data.list.map((item)=>{
                  if(item.opinion){
                     this.suggest = item.opinion
                  }  
                  if(item.remarks){
                     this.remark=item.remarks
                 }
               })
            } else {
               this.$message.warning(res.data.meta.message)
            }
        })
        .catch(function (res) {
           console.log(res)
        })
    },
  }
}
</script>

